package com.fy56.platform.goodsTracking.web;

import org.apache.log4j.Logger;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.net.ConnectException;

/**
 * Created by XTK on 2016-11-24.
 */
public class WebServiceUtil {
    static Logger log = Logger.getLogger(WebServiceUtil.class);



    /**
     * webService接口
     *
     * @param Method
     * @param mySoapObject
     * @return
     */
    public static String DoService_Reslut(String WNS, String WURL,String Method, final SoapObject mySoapObject) throws ConnectException {
        String sResult = "";
        try {
            System.out.print("上传开始：DoService_Reslut ");
            HttpTransportSE ht = new HttpTransportSE(WURL);
            ht.debug = true;
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.bodyOut = mySoapObject;
            envelope.encodingStyle = "UTF-8";
            envelope.setOutputSoapObject(mySoapObject);
            ht.call(WNS + Method, envelope);
            if (envelope.getResponse() != null) {
                SoapObject result = (SoapObject) envelope.bodyIn;
                sResult = result.getProperty(0).toString();
            }
        } catch (ConnectException e) {
            throw e;
        } catch (Exception e) {
            System.out.print("上传错误：DoService_Reslut " + e.getMessage());
            sResult = "error";
        }
        return sResult;
    }
}
